package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.common.entity.R;
import cn.zysuyuan.item.entity.ProductbaseMedicinalGone;
import cn.zysuyuan.item.service.ProductbaseMedicinalGoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-02-12 10:46
 */

@Api(tags = "基地中某个药材的原料去向")
@RestController
@RequestMapping("productbaseMedicinalGone")
public class ProductbaseMedicinalGoneController {

    @Autowired
    private ProductbaseMedicinalGoneService productbaseMedicinalGoneService;

    @ApiOperation(value = "基地中某个药材的原料去向的表格数据获取", notes = "基地中的某个药材的原料去向管理")
    @GetMapping("/productbaseMedicinalGoneData")
    public ResponseEntity<PageResult<ProductbaseMedicinalGone>> selectList(@RequestParam Map<String,Object> map){
        PageResult<ProductbaseMedicinalGone> result = productbaseMedicinalGoneService.selectList(map);
        if (CollectionUtils.isEmpty(result.getRows())) {
            List<ProductbaseMedicinalGone> list = new ArrayList<ProductbaseMedicinalGone>();
            result.setRows(list);
            return  ResponseEntity.ok(result);
        }
        return  ResponseEntity.ok(result);
    }

    @ApiOperation(value = "保存信息", notes = "保存信息")
    @PostMapping("/productbaseMedicinalGoneData")
    public R save(@RequestBody ProductbaseMedicinalGone productbaseMedicinalGone) {
        //System.out.println("#####################test ready to insert");
        productbaseMedicinalGoneService.insert(productbaseMedicinalGone);
        return R.ok();
    }

    @ApiOperation(value = "删除信息", notes = "删除信息")
    @DeleteMapping("/productbaseMedicinalGoneData")
    public R delete(@ApiParam(value = "基地中的某种药材的原料去向id") @RequestParam("id") String id) {
        productbaseMedicinalGoneService.delete(id);
        return R.ok();
    }

    @ApiOperation(value = "修改信息", notes = "修改信息")
    @PutMapping("/productbaseMedicinalGoneData")
    public R update(@RequestBody ProductbaseMedicinalGone productbaseMedicinalGone) {
        productbaseMedicinalGoneService.update(productbaseMedicinalGone);
        return R.ok();
    }
}